package src;

import javax.swing.*;
import java.awt.*;

public class SecondPage extends JFrame {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    JTextField[] textOfCoefficient_C;//价值系数C
    JTextField[] textOfCoefficient_B;//限额系数B
    JTextField[][] textOfMatrixA;//技术系数A
    JLabel[] variableXOfC;//目标函数的X
    JLabel[][] variablesX;//矩阵中的X
    JLabel[] labelOfB;
    JLabel[] textOfLeft;//左边的标签
    JLabel labelOfMaxOrMin;//最大最小值选项的标签
    JComboBox<String>[] optionsOfSymbols;//大于等于小于号
    JComboBox<String>[] optionsOfUnconstrainedVariable;//有无非约束变量的选项
    JComboBox<String> maxOrMin;//求最大值和最小值的选项
    String[] symbol = {"=", "≥", "≤",};//optionsOfSymbols中的符号
    String[] textOfUnconstrainedVariable = {"否", "是",};//optionsOfUnconstrainedVariable中的符号
    String[] optionsOfMaxOrMin = {"MAX", "MIN",};
    JButton nextStep;
    static final int DATUMMARKx = 75;//左上角的基准坐标x
    static final int DATUMMARKy = 50;//左上角的基准坐标y


    SecondPage(boolean isVisible){
        this.setVisible(isVisible);
    }


    SecondPage(int height, int width){
        Container contentPane = this.getContentPane();
        contentPane.setLayout(null);

        this.setTitle("单纯形法计算器【作者王勾勾_QQ740597991】");
        textOfCoefficient_C = new JTextField[width];
        textOfCoefficient_B = new JTextField[height];
        textOfMatrixA = new JTextField[height][width];
        variableXOfC = new JLabel[width];
        variablesX = new JLabel[height][width];
        labelOfB = new JLabel[height];
        textOfLeft = new JLabel[height+2];
        optionsOfSymbols = new JComboBox[height];
        optionsOfUnconstrainedVariable = new JComboBox[width];



        //添加启动按钮
        nextStep = new JButton("开始计算");
        nextStep.setBounds(DATUMMARKx+100+100*width, DATUMMARKy+50+50*height, 120, 20);
        contentPane.add(nextStep);


        //添加大小选项
        maxOrMin = new JComboBox<String>(optionsOfMaxOrMin);
        maxOrMin.setBounds(DATUMMARKx+100+100*width, DATUMMARKy, 60, 20);
        contentPane.add(maxOrMin);


        //添加大小选项的说明标签
        labelOfMaxOrMin = new JLabel("<html>选择目标函数是<br>最大值or最小值</html>");
        labelOfMaxOrMin.setBounds(DATUMMARKx+170+100*width, DATUMMARKy-7, 100, 40);
        contentPane.add(labelOfMaxOrMin);


        for(int j=0;j<width;j++) {
            //添加C的系数
            textOfCoefficient_C[j] = new JTextField();
            textOfCoefficient_C[j].setBounds(DATUMMARKx+100+100*j, DATUMMARKy, 50, 20);
            textOfCoefficient_C[j].setHorizontalAlignment(JTextField.RIGHT);
            contentPane.add(textOfCoefficient_C[j]);

            //添加C的X标签
            variableXOfC[j] = new JLabel("X"+(j+1));
            variableXOfC[j].setBounds(DATUMMARKx+155+100*j,DATUMMARKy,36,20);
            contentPane.add(variableXOfC[j]);

            //添加是否为非约束变量的选项
            optionsOfUnconstrainedVariable[j] = new JComboBox<String>(textOfUnconstrainedVariable);
            optionsOfUnconstrainedVariable[j].setBounds(DATUMMARKx+100+100*j, DATUMMARKy+50+50*height, 50, 20);
            contentPane.add(optionsOfUnconstrainedVariable[j]);

            //添加技术系数及其X
            for(int i=0;i<height;i++) {
                textOfMatrixA[i][j] = new JTextField();
                variablesX[i][j] = new JLabel("X"+(j+1));
                textOfMatrixA[i][j].setBounds(DATUMMARKx+100+100*j, DATUMMARKy+50+50*i, 50, 20);
                variablesX[i][j].setBounds(DATUMMARKx+155+100*j, DATUMMARKy+50+50*i, 36, 20);
                textOfMatrixA[i][j].setHorizontalAlignment(JTextField.RIGHT);
                contentPane.add(textOfMatrixA[i][j]);
                contentPane.add(variablesX[i][j]);
            }
        }

        //添加左边标签
        for(int i=0; i<height+2; i++) {
            if(i == 0) {
                textOfLeft[i] = new JLabel("目标函数");
            }
            else if(i == height+1) {
                textOfLeft[i] = new JLabel("是否为非约束变量");
            }
            else {
                textOfLeft[i] = new JLabel("第"+i+"行约束");
            }
            textOfLeft[i].setBounds(DATUMMARKx-30, DATUMMARKy+0+50*i, 120, 20);
            contentPane.add(textOfLeft[i]);
        }



        for(int i=0; i<height; i++) {
            //添加符号
            optionsOfSymbols[i] = new JComboBox<String>(symbol);
            optionsOfSymbols[i].setBounds(DATUMMARKx+100+100*width, DATUMMARKy+50+50*i, 50, 20);
            contentPane.add(optionsOfSymbols[i]);

            //添加限额系数B
            textOfCoefficient_B[i] = new JTextField();
            textOfCoefficient_B[i].setBounds(DATUMMARKx+170+100*width, DATUMMARKy+50+50*i, 50, 20);
            contentPane.add(textOfCoefficient_B[i]);

            //添加限额系数B的标签
            labelOfB[i] = new JLabel("b"+(i+1));
            labelOfB[i].setBounds(DATUMMARKx+225+100*width, DATUMMARKy+50+50*i, 50, 20);
            contentPane.add(labelOfB[i]);
        }



        this.setSize(400+(width)*100, 250+(height)*50);
        this.setLocationRelativeTo(null);//居中
        this.setResizable(false);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        contentPane.setVisible(true);


    }
}












